import 'dart:convert' show json;

import 'package:loxen/mode/user.dart';

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }

  return null;
}

class MineCommentBean {
  MineCommentBean({
    this.code,
    this.data,
  });

  factory MineCommentBean.fromJson(Map<String, dynamic> jsonRes) =>
      jsonRes == null
          ? null
          : MineCommentBean(
        code: asT<int>(jsonRes['code']),
        data: Data.fromJson(asT<Map<String, dynamic>>(jsonRes['data'])),
      );

  int code;
  Data data;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'code': code,
    'data': data,
  };

  @override
  String toString() {
    return json.encode(this);
  }
}


class Data {
  int count;
  String next;
  String previous;
  List<MineComment> results;

  Data({this.count, this.next, this.previous, this.results});

  Data.fromJson(Map<String, dynamic> json) {
    count = json['count'];
    next = json['next'];
    previous = json['previous'];
    if (json['results'] != null) {
      results = new List<MineComment>();
      json['results'].forEach((v) {
        results.add(new MineComment.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['count'] = this.count;
    data['next'] = this.next;
    data['previous'] = this.previous;
    if (this.results != null) {
      data['results'] = this.results.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class MineComment {
  String instanceId;
  String content;
  String brief;
  String cover;
  User user;
  User infoUser;
  String title;
  String contentType;
  String addTime;

  MineComment(
      {this.instanceId,
        this.content,
        this.brief,
        this.cover,
        this.user,
        this.infoUser,
        this.title,
        this.contentType,
      this.addTime});

  MineComment.fromJson(Map<String, dynamic> json) {
    instanceId = json['instance_id'];
    content = json['content'];
    brief = json['brief'];
    cover = json['cover'];
    user = json['user'] != null ? new User.fromJson(json['user']) : null;
    infoUser = json['info_user'] != null
        ? new User.fromJson(json['info_user'])
        : null;
    title = json['title'];
    contentType = json['content_type'];
    addTime = json['add_time'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['instance_id'] = this.instanceId;
    data['content'] = this.content;
    data['brief'] = this.brief;
    data['cover'] = this.cover;
    if (this.user != null) {
      data['user'] = this.user.toJson();
    }
    if (this.infoUser != null) {
      data['info_user'] = this.infoUser.toJson();
    }
    data['title'] = this.title;
    data['content_type'] = this.contentType;
    data['add_time'] = this.addTime;
    return data;
  }
}


